package com.example.springbootbook2.service;

import com.example.springbootbook2.mapper.UserInfoMapper;
import com.example.springbootbook2.model.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class UserInfoService {
    @Autowired
    private UserInfoMapper userInfoMapper;

    public String login(UserInfo userInfo) {
        if (userInfo == null || !StringUtils.hasLength(userInfo.getUserName())
        || !StringUtils.hasLength(userInfo.getPassword())) {
            return "输入的用户名或者密码存在空项，请检查后再登录";
        }
        UserInfo userInfo1 = null;
        try {
            userInfo1 = userInfoMapper.getUser(userInfo.getUserName());
            if (userInfo1 == null) return "当前用户不存在，请注册后再登录吧";
            if (userInfo1.getPassword().equals(userInfo.getPassword())) return "";
            else return "账号或密码错误";
        } catch (Exception e) {
            return "登录过程出现错误，请联系管理员" + e.getMessage();
        }
    }
}
